package com.wanmait.deliverymangementsystem.usercontroller;

import com.github.pagehelper.PageInfo;
import com.wanmait.deliverymangementsystem.pojo.HistoryOrders;
import com.wanmait.deliverymangementsystem.pojo.Users;
import com.wanmait.deliverymangementsystem.service.HistoOrderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserHistoryOrderController {
    @Resource
    private HistoOrderService histoOrderService;
    @GetMapping("historyOrders")
    public PageInfo<HistoryOrders> historyOrders(HttpSession session, Model model,Integer page){
        Users users =(Users)session.getAttribute("user");
        if (page==null)
            page=0;
        PageInfo<HistoryOrders> historyOrdersList =    histoOrderService.findAllByUserIDandPageNo(users.getId(),page);
         model.addAttribute("historyOrdersList",historyOrdersList);
            return historyOrdersList;
    }
    @GetMapping("deleteHistoryOrders")
    public String deleteHistoryOrders(Integer id){
        histoOrderService.deleteUserByID(id);
        return "redirect:/user/historyOrders";
    }
}
